package com.yiyuzi.wiki.common.constant;

import java.util.Arrays;

/**
 * 可维护的返回码
 *
 * @author yiyuzi
 * @date 2021/5/6 23:29
 */

public enum ResponseCodeEnum {
    SUCCESS(200, "成功"),
    ERROR(500, "系统错误"),
    FAIL(999,"操作失败"),

    LOGIN_FAIL(400,"登录失败"),
    TOKEN_INVALID(401,"登录状态失效"),
    LOGOUT_FAIL(402,"退出失败"),
    NO_PRIVILEGE(403,"无权限"),
    NOTFOUND(404,"找不到数据"),

    USER_NOTFOUND(1000, "找不到用户"),
    USER_INFO_NULL(1001, "用户信息不能为空"),
    USER_NAME_EXIST(1002, "用户名已存在"),

    ROLE_NOTFOUND(2000, "找不到角色"),
    ROLE_INFO_NULL(2001,"角色信息不能为空"),

    ALREADY_EXIST(3001,"数据已存在"),
    ID_NULL(3002,"id不能为空");

    private Integer value;
    private String desc;

    ResponseCodeEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDescByValue(Integer status) {
        ResponseCodeEnum[] values = ResponseCodeEnum.values();
        String desc = Arrays.stream(values).filter(e -> e.getValue().equals(status)).findFirst().get().getDesc();
        return desc;
    }
}
